package com.qiangqiang.task.server.mapper;

import com.qiangqiang.task.server.entity.Task;
import com.qiangqiang.task.server.mapper.provider.TaskMapperProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskMapper {

    @InsertProvider(type = TaskMapperProvider.class, method = "insertTask")
    int insertTask(@Param("task") Task task);

    @Select("select * from task where task_id=#{taskId}")
    Task findByTaskId(@Param("taskId") long taskId);

    @Update("update task set receiver_id=#{receiverId},status=1  where task_id=#{taskId}")
    int updateTaskByReceiverId(@Param("receiverId") long receiverId, @Param("taskId") long taskId);

    @Select("select user_id from task where task_id=#{taskId}")
    long findUserIdByTaskId(@Param("taskId") long taskId);

    @Select("select status from task where task_id=#{taskId}")
    Integer findStatusByTaskId(@Param("taskId") long taskId);

    @SelectProvider(type = TaskMapperProvider.class, method = "queryTaskByStatus")
    List<Task> findAllByStatus(@Param("page") int page, @Param("pageSize") int pageSize);

    @SelectProvider(type = TaskMapperProvider.class,method = "queryAllByUserId")
    List<Task> findAllByUserId(@Param("page") int page, @Param("pageSize") int pageSize,
                               @Param("userId") long userId,@Param("isReceviedId") boolean isReceviedId);

    @Update("update task set status=#{status} where task_id=#{taskId}")
    int updateStatusByTaskId(@Param("taskId") long taskId,@Param("status") int status);
}
